package com.liukai.personalbills.service.impl;

import com.liukai.personalbills.dao.AccountDao;
import com.liukai.personalbills.entity.Account;
import com.liukai.personalbills.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public List<Account> findAllAccount(String username) {

        // 查找该用户名的id
        int id = accountDao.findIdByUser(username);
        // 根据id查找账单
        List<Account> accounts = accountDao.findAll(id);

        return accounts;
    }

    @Override
    public int addAccount(Account account, String username) {
        // 查找该用户名的id
        int id = accountDao.findIdByUser(username);
        account.setId(id);
        System.out.println("Service:"+account.toString());
        int result = accountDao.save(account);
        return result;
    }

    @Override
    public int updateAccount(Account account, String username) {
        // 查找该用户名的id
        int id = accountDao.findIdByUser(username);
        account.setId(id);
        System.out.println("Service:"+account.toString());
        int result = accountDao.update(account);
        return result;
    }


}
